home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / sysdeps / mach / hurd / i386 / __sigret.c next >
Encoding:
C/C++ Source or Header  |  1994-08-22  |  3.7 KB  |  124 lines

  1. /* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. register int *sp asm ("%esp");
  20.  
  21. #include <hurd.h>
  22. #include <hurd/signal.h>
  23. #include <hurd/threadvar.h>
  24. #include <hurd/msg.h>
  25. #include <stdlib.h>
  26.  
  27. int
  28. __sigreturn (struct sigcontext *scp)
  29. {
  30.   struct hurd_sigstate *ss;
  31.   mach_port_t *reply_port;
  32.  
  33.   if (scp == NULL || (scp->sc_mask & _SIG_CANT_MASK))
  34.     {
  35.       errno = EINVAL;
  36.       return -1;
  37.     }
  38.  
  39.   ss = _hurd_self_sigstate ();    /* SS->lock now locked.  */
  40.  
  41.   /* Restore the set of blocked signals, and the intr_port slot.  */
  42.   ss->blocked = scp->sc_mask;
  43.   ss->intr_port = scp->sc_intr_port;
  44.  
  45.   /* Check for pending signals that were blocked by the old set.  */
  46.   if (ss->pending & ~ss->blocked)
  47.     {
  48.       /* There are pending signals that just became unblocked.  Wake up the
  49.      signal thread to deliver them.  But first, squirrel away SCP where
  50.      the signal thread will notice it if it runs another handler, and
  51.      arrange to have us called over again in the new reality.  */
  52.       ss->context = scp;
  53.       /* Clear the intr_port slot, since we are not in fact doing
  54.      an interruptible RPC right now.  If SS->intr_port is not null,
  55.      the SCP context is doing an interruptible RPC, but the signal
  56.      thread will examine us while we are blocked in the sig_post RPC.  */
  57.       ss->intr_port = MACH_PORT_NULL;
  58.       __mutex_unlock (&ss->lock);
  59.       __sig_post (_hurd_msgport, 0, __mach_task_self ());
  60.       /* If a pending signal was handled, sig_post never returned.  */
  61.       __mutex_lock (&ss->lock);
  62.     }
  63.  
  64.   if (scp->sc_onstack)
  65.     {
  66.       ss->sigaltstack.ss_flags &= ~SA_ONSTACK; /* XXX threadvars */
  67.       /* XXX cannot unlock until off sigstack */
  68.       abort ();
  69.     }
  70.   else
  71.     __mutex_unlock (&ss->lock);
  72.  
  73.   /* Destroy the MiG reply port used by the signal handler, and restore the
  74.      reply port in use by the thread when interrupted.  */
  75.   reply_port =
  76.     (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY);
  77.   if (*reply_port)
  78.     __mach_port_destroy (__mach_task_self (), *reply_port);
  79.   *reply_port = scp->sc_reply_port;
  80.  
  81.   if (scp->sc_fpused)
  82.     {
  83.   /* XXX should restore FPU state here XXX roland needs 387 manual */
  84.       abort ();
  85.     }
  86.  
  87.   {
  88.     /* There are convenient instructions to pop state off the stack, so we
  89.        copy the registers onto the user's stack, switch there, pop and
  90.        return.  */
  91.  
  92.     int *usp = (int *) scp->sc_uesp;
  93.  
  94.     *--usp = scp->sc_eip;
  95.     *--usp = scp->sc_efl;
  96.     memcpy (usp -= 12, &scp->sc_i386_thread_state, 12 * sizeof (int));
  97.  
  98.     sp = usp;
  99.  
  100. #define A(line) asm volatile (#line)
  101.     /* The members in the sigcontext are arranged in this order
  102.        so we can pop them easily.  */
  103.  
  104.     /* Pop the segment registers (except %cs and %ss, done last).  */
  105.     A (popl %gs);
  106.     A (popl %fs);
  107.     A (popl %es);
  108.     A (popl %ds);
  109.     /* Pop the general registers.  */
  110.     A (popa);
  111.     /* Pop the processor flags.  */
  112.     A (popf);
  113.     /* Return to the saved PC.  */
  114.     A (ret);
  115.  
  116.     /* Firewall.  */
  117.     A (hlt);
  118. #undef A
  119.   }
  120.  
  121.   /* NOTREACHED */
  122.   return -1;
  123. }
  124.